/*
 *  BlobDetectionSDL.h
 *  portVideoBlobDetection
 *
 *  Created by Pawel 'solydzajs' Solyga on 7/25/07.
 *  Copyright 2007 __MyCompanyName__. All rights reserved.
 *
 */
#ifndef __BLOBDETECTIONSDL_H__
#define __BLOBDETECTIONSDL_H__

#include <SDL.h>
#include "ITouchListener.h"
#include "BlobDetection.h"
#include "Blob.h"
#include "../SDL_primitives/SDL_Line.h"
#include "SFont.h"


class BlobDetectionSDL: public ITouchListener
{
private:
	SDL_Surface *image;
	Uint32 edgeColor;
	Uint32 rectColor;
	Uint32 numberFontColor;
	SFont_Font *sfont;
	int fontHeight;
	int *imageData;
	float threshold;
	int dimMinX;
	int dimMinY;
	bool isDrawBlobs;
	bool gotSurface;
	bool isDrawBlobNumber;
	bool isDrawBlobEdges;
	bool isDrawBlobRect;
	
	blobDetection::BlobDetection bd;
	blobDetection::Blob b;
	blobDetection::EdgeVertex eA,eB;
	
public:
	BlobDetectionSDL(SDL_Surface *frame);
	~BlobDetectionSDL();

	void drawBlobRectangle(float x1, float y1, float x2, float y2);
	void drawBlobEdges(blobDetection::Blob &blob);
	void drawBlobNumber(int number, float x, float y);
	void convertFrame();
	void setImage(SDL_Surface *newImage);
	void setThreshold(float threshold);
	void setBlobDimensionMin(int x,int y);
	void setBlobRectangleColor(Uint8 r, Uint8 g, Uint8 b);
	void setBlobEdgesColor(Uint8 r, Uint8 g, Uint8 b);
	void setBlobNumberFontColor(Uint8 r, Uint8 g, Uint8 b);
	void setDrawBlobs(bool drawBlobs);
	blobDetection::BlobDetection* getBlobDetectionAlgorithm();
	void findBlobs();
	void process();
	void drawBlobs();
	void setDrawBlobNumber(bool drawBlobNumber);
	void setDrawBlobEdges(bool drawBlobEdges);
	void setDrawBlobRect(bool drawBlobRect);
	
	//! Notify that a finger has just been made active. 
	virtual void fingerDown(TouchData data)
	{
		drawBlobNumber(data.ID, data.X, data.Y);
	}

	//! Notify that a finger has moved 
	virtual void fingerUpdate(TouchData data)
	{
		drawBlobNumber(data.ID, data.X, data.Y);
	}

	//! A finger is no longer active..
	virtual void fingerUp(TouchData data)
	{
		drawBlobNumber(data.ID, data.X, data.Y);		
	}

};

#endif